package com.formula.propertyshop.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.formula.propertyshop.R;
import com.squareup.picasso.Picasso;

public class PropertyImagePagerAdapter extends PagerAdapter{
	private Context context;
	private String listImgGalleryUrl[];
	public PropertyImagePagerAdapter(Context c, String[] urls) {
		this.context = c;
		this.listImgGalleryUrl = urls;
	}
	@Override
	public int getCount() {
		return listImgGalleryUrl.length;
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == (RelativeLayout)arg1;
	}
	public Object instantiateItem(ViewGroup container, int position) {
		LayoutInflater inflater = (LayoutInflater) this.context
	                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	    View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, container,
	                false);
	    ImageView imageView = (ImageView) viewLayout.findViewById(R.id.imgDisplay);
        String url =listImgGalleryUrl[position].toString();
        Picasso.with(context).load(url).fit().centerInside().error(R.drawable.noimage).placeholder(R.drawable.noimage).into(imageView);
        ((ViewPager) container).addView(viewLayout);
        return viewLayout;
    }
	@Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        ((ViewPager) container).removeView((RelativeLayout) object);
  
    }
}
